home *** CD-ROM | disk | FTP | other *** search
- /*
- * This program illustrates relation between CONVOLUTION and CORRELATION
- *
- * Correlation is equivalent to convolution with Flipped array
- */
- #include <stdio.h>
- #include <math.h>
- #include "conv.h"
-
- void float_seq_print( float *f_array, int n_pts);
- #define NPTS 8
-
- main() {
- int i;
- float seq1[NPTS], seq2[NPTS], cor1[NPTS], cor2[NPTS];
-
- /* Initialize Sequences ... seq2 is seq1 shifted by two samples */
- seq1[0] = seq1[1] = seq2[NPTS-2] = seq2[NPTS-1] = 0.;
- for (i = 2; i < NPTS ; i++)
- seq1[i] = seq2[i-2] = 10. * pow( -.3, (double)i);
-
- /* Correlation */
- scor1d( seq1,1,0,NPTS,seq2,1,0,NPTS,cor1,1,0,NPTS);
-
- /* Convolution with flipped array */
- /* We actually just call sfir1d with the flipping parameters */
- /* New origin of array is last sample, new increment is -(old increment) */
- sfir1d( seq1,1,0,NPTS,seq2+(NPTS-1),-1,-(NPTS-1),NPTS,cor2,1,0,NPTS,1.,0.);
-
- /* Print out the Input sequences and the Correlation functions */
- printf("Seq # 1 : \n");
- float_seq_print( seq1, NPTS);
- printf("Seq # 2 : \n");
- float_seq_print( seq2, NPTS);
- printf("Correlation using \"scor1d\" : \n");
- float_seq_print( cor1, NPTS);
- printf("Correlation using \"sfir1d\" : \n");
- float_seq_print( cor2, NPTS);
- }
- void float_seq_print( float *f_array, int n_pts){
- for ( ; n_pts > 0; n_pts--)
- printf("%9.5f", *f_array++);
- printf("\n");
- }
-